package net.monare.mifss.lib.validators;

import net.monare.mifss.configurations.pojo.ContentPoolDef;
import net.monare.mifss.configurations.pojo.StorageDef;
import net.monare.mifss.exceptions.ConfigurationHandlerException;
import net.monare.mifss.exceptions.ValidatorException;

import java.util.HashSet;

/**
 * Created by kristan_uros on 9.4.2014.
 */
public class PoolValidator extends  BaseValidator {

    public void validatePools(StorageDef storageDef) throws ValidatorException {

        //
        // Check for id duplication in pools under one storage
        HashSet<Integer> pooIdSet = new HashSet<Integer>();
        for (ContentPoolDef poolDef : storageDef.getContentPoolDefs()) {

            Integer poolId = new Integer(poolDef.getId());

            if (pooIdSet.contains(poolId)) {

                String errMessage = "Duplicated id detected for content pool: " + poolDef.getTitle() + " !";
                logger.error(errMessage);
                throw new ValidatorException(errMessage);

            } else {
                pooIdSet.add(poolId);
            }

        }

    }

}
